package com.common.utils;


import lombok.Data;

import java.io.Serializable;

/**
 * 全局统一返回结构
 */
@Data
public class R<T>  implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回消息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;


    public static <T> R<T> success(T data) {
        R<T> R= new R<>();
        R.setCode(200);
        R.setMsg("成功");
        R.setData(data);
        return R;
    }

    public static <T> R<T> success(Integer code,T data){
        R<T> result= new R<>();
        result.setCode(code);
        result.setMsg("成功");
        result.setData(data);
        return result;
    }

    public static <T> R<T> success(Integer code,String message){
        R<T> result= new R<>();
        result.setCode(code);
        result.setMsg(message);
        return result;
    }

    public static <T> R<T> success() {
        R<T> resultDto = new R<>();
        resultDto.setCode(200);
        resultDto.setMsg("成功");
        return resultDto;
    }

    public static <T> R<T> fail() {
        R<T> resultDto = new R<>();
        resultDto.setCode(1000);
        resultDto.setMsg("失败");
        return resultDto;
    }

    public static <T> R<T> fail(String msg) {
        R<T> resultDto = new R();
        resultDto.setCode(500);
        resultDto.setMsg(msg);
        return resultDto;
    }



}
